import { LogConst } from "src/consts/log_const";
import * as Api from 'src/api/net';
import { PopupName } from "src/consts/popup_const";

const state: ListMsgData = {} as any;
// StateIniter.init(state, 'demo');

state.curr_page = 1;
state.page_size = 15;
state.total_page = 1;
state.total_size = 1;
state.data_list = [];
state.type = "";
// vuex

/** 更新数据的 */
const mutations = {
    [LogConst.CommitLogList](state: ListMsgData, data: ListMsgData): void {
        console.log("log data update", data);
        state.curr_page = data.curr_page;
        state.page_size = data.page_size;
        state.total_page = data.total_page;
        state.total_size = data.total_size;
        let len = data.data_list.length;
        for (let i = 0; i < len; i++) {
            let tmp: DemoData = data.data_list[i];
            tmp.selected = false;
        }
        state.data_list = data.data_list;
    },
    [LogConst.CommitType](state: ListMsgData, data: String): void {
        state.type = data
    }
}

//异步处理
const actions = {
    [LogConst.DispatchLogList](context: VuexData, data?: any): void {
        Api.AjaxPost(Config.ajaxUrl + "/webhistory/list.do", data, (res: any) => {
            if (isNoEmptyObject(res.data)) {
                WLCommit(LogConst.CommitLogList, res.data);
            }
        })
    }
}


export default {
    state,
    mutations,
    actions
}